package com.warski.wonderfires.dlna.model;

import com.warski.wonderfires.dlna.type.EnumDeviceStatus;
import com.warski.wonderfires.dlna.type.EnumDeviceType;
import com.warski.wonderfires.dlna.type.EnumServiceType;
import org.fourthline.cling.model.meta.Device;
import org.fourthline.cling.model.meta.Service;

/**
 * Created by xuhaiping on 2020/9/2.
 * dlna设备
 */
public class DeviceInfo {
    private Device device;
    private String name;
    private String nickname;
    private EnumDeviceStatus state;

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public Device getDevice() {
        return device;
    }

    public void setDevice(Device device) {
        this.device = device;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public EnumDeviceStatus getState() {
        return state;
    }

    public void setState(EnumDeviceStatus state) {
        this.state = state;
    }

    public DeviceInfo(Device device) {
        this.device = device;
        if (device.getDetails() != null && device.getDetails().getFriendlyName() != null) {
            this.name = device.getDetails().getFriendlyName();
        } else {
            this.name = device.getDisplayString();
        }
        this.nickname = "";
        this.state = EnumDeviceStatus.UNKNOWN;
    }

    public boolean isConnected(){
        return state != EnumDeviceStatus.DISCONNECTED && state != EnumDeviceStatus.UNKNOWN;
    }

    public Service findService(EnumServiceType serviceType){
        if(device == null){
            return null;
        }
        return device.findService(serviceType.getType());
    }
}
